<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<title>中纺互联</title>
		<link rel="stylesheet" type="text/css" href="css/aui.css" />
		<link rel="stylesheet" type="text/css" href="css/common.css" />
		<style>
			header{
				background: #fff;
				font-size: 16px;
			}
			.aui-nav .aui-bar-tab {
				border-top: 1px solid #eee;
			}
			.title2{
				text-align: center;
				padding: 10px;
				position: relative;
			}
			.edit{
				position: absolute;
				right: 15px;
				
				font-size: 12px;
				top: 50%;
				margin-top:-6px;
				z-index: 999;
			}
			.hidde{
				display: none;
			}
			.showHeader{
				display: block;
			}
			.header1{
				/*padding:10px 10px;*/
				line-height: 45px;
				height: 45px;
			}
			.header1 .aui-title{
				left: 80px;
				right:80px;
				width: auto !important;
			}
			.header1 .aui-iconfont{
				font-size: 18px;
				line-height: 45px;
				height: 45px;
				padding-left:10px;
			}
			/*人脉圈*/
			.header3{
				background: #327afa;
				position: relative;
				padding: 12px;
			}
			.header3 .aui-tab-nav.aui-tab-border{
			    border-color:#fff;
			}
			.header3 .aui-tab-nav.aui-tab-border li{
			    height: 35px;
			    line-height: 35px !important;
			    color:#fff;
			    background: transparent;
			}
			.header3 .aui-list-view{
			    margin-bottom: 8px;
			}
			.header3  .aui-tab-nav.aui-tab-border li.active{
			    color: #327afa;
			    background: #fff;
			    border-bottom: 2px #327afa solid;
			}
			.header3 .header-icon{
			    position: absolute;
			    top:50%;
			    margin-top: -16px;
			    right: 0px;
			    color:#fff;
			}
			.header3 .header-icon .aui-icon-add,
			.header3 .header-icon .aui-icon-cameraadd{
				padding:10px 10px 10px 4px;margin: 0;
			}
			.aui-icon-add{
				/*border: 5px solid transparent;*/
			}
			.header3 .header-icon .aui-iconfont{
			    font-size: 20px;
			}
			.header3 .aui-tab-nav{
				width: 50%;
				margin: 0 auto;
				font-size: 13px;
				border:1px solid #fff;
				height: 35px;
				line-height: 35px !important;
			}
			.aui-nav .aui-bar-tab .active{
				color:#327afa;
			}
			.myMessage {
				position: relative;
			}

			.myMessage:before {
				content: "";
				position: absolute;
				width: 8px;
				height: 8px;
				border-radius: 50%;
				background: red;
				right: -6px;
				top: -6px;
			}
		</style>
	</head>
	<body>
		<header class="" id="aui-header aui-border-b">
			<!-- 首页 -->
			<div class=" header1  hidde aui-border-b" id="header-title">
				<div class="aui-pull-left aui-iconfont aui-icon-sort icon-left-coler" tapmode onclick="openToTwo('html/fenlei_win')" style="padding-right:15px !important;"></div>
				<div class="aui-title">
				    中纺互联
				</div>
				<div class="aui-pull-right aui-iconfont aui-icon-search icon-left-coler" tapmode onclick="showSearch();" style="padding-left:30px !important; padding-right:15px !important;"></div>
			</div>
			<!-- 动态圈 -->
			<div class="divHeader header2 hidde aui-border-b">
				<div class="aui-tab">
					<ul class="aui-tab-nav">
				        <li class="active" data-type="1" tapmode onclick="changeHeader2(this)">动态</li>
				        <li  data-type="2" tapmode onclick="changeHeader2(this)">热门</li>
				    </ul>
				</div>
			</div>
			<!-- 人脉圈 -->
		    <div class="aui-tab header3 hidde">
		        <ul class="aui-tab-nav aui-tab-border headType">
		            <li class="active" data-type="1" tapmode onclick="headerChange(this)">行业人脉</li>
		            <li  data-type="2"  tapmode onclick="headerChange(this)">我的人脉</li>
		        </ul>
		        <div class="header-icon ">
				    <i class="aui-iconfont aui-icon-add" tapmode onclick="openToTwo('html/friend/contact_win')"></i>
				    <i class="aui-iconfont aui-icon-cameraadd " tapmode onclick="changeAvatar()"></i>
			    </div>
		    </div>
			<!-- 进货单 -->
			<div class="title2 header4 hidde aui-border-b">
				<span>进货单</span>
				<span class="edit" tapmode onclick="edit(this)" style="font-size: 16px;margin: 0;line-height: 0;display: none;">编辑</span>
			</div>
		</header>
		<footer class="aui-nav" id="aui-footer">
			<ul class="aui-bar-tab">
				<li class="active" id="tabbar1" tapmode onclick="randomSwitchBtn(this,'首页',0)">
					<span class="aui-iconfont aui-icon-home"></span>
					<p>
						首页
					</p>
				</li>
				<li id="tabbar2" tapmode onclick="randomSwitchBtn(this,'动态圈',1)">
					<span class="aui-iconfont aui-icon-read"></span>
					<p>
						动态圈
					</p>
				</li>
				<li id="tabbar3" tapmode onclick="randomSwitchBtn(this,'人脉圈',2)">
					<span class="aui-iconfont aui-icon-friend"></span>
					<p>
						人脉圈
					</p>
				</li>
				<li id="tabbar4" tapmode onclick="randomSwitchBtn(this,'进货单',3)">
					<span class="aui-iconfont aui-icon-form"></span>
					<p>
						进货单
					</p>
				</li>
				<li id="tabbar5" tapmode onclick="randomSwitchBtn(this,'',4)">
					<span class="noMessage"><span class="aui-iconfont aui-icon-my"></span></span>
					<p>
						我的
					</p>
				</li>
			</ul>
		</footer>
	</body>
	<script type="text/javascript" src="script/api.js"></script>
	<script type="text/javascript" src="script/common.js"></script>
	<script type="text/javascript" src="script/myInfo.js"></script>
	<script type="text/javascript" src="script/mui.js"></script>
	<script type="text/javascript" src="script/jquery-1.11.3.js"></script>
	<script type="text/javascript">
		apiready = function() {
			var usingServerUrl = $api.getStorage('_server_url');
			if(usingServerUrl!=serverUrl){
				$api.clearStorage();
			}

			back();
			//isLogin();
            mask=mui.createMask();//遮罩
			api.parseTapmode();
			var header = $api.dom('header');
			$api.fixIos7Bar(header);
			api.setStatusBarStyle({
                  style : 'dark'
            });

			header_h = $api.offset(header).h;
			body_h = $api.offset($api.dom('body')).h;
		    footer_h = $api.offset($api.byId('aui-footer')).h;
		    var statusbarHeight=api.systemType=='ios'?20.0:0.0;
			api.openFrameGroup({
				name : 'footer_tab_nav',
				scrollEnabled : false,
				rect : {
					x : 0,
					y : header_h,
					//y: 0,
					w : 'auto',
					h : body_h - header_h - footer_h
					//h : body_h - footer_h
				},
				index : 0,
				preload : 2,
				frames : [{
					name : 'footer_tab_1',
					url : 'html/footer_tab_1.html',
					bounces : true,
					vScrollBarEnabled : false,
					hScrollBarEnabled : false
				}, {
					name : 'footer_tab_2',
					url : 'html/footer_tab_2.html',
					bounces : true,
					vScrollBarEnabled : false,
					hScrollBarEnabled : false
				}, {
					name : 'footer_tab_3',
					url : 'html/footer_tab_3.html',
					bounces : true,
					vScrollBarEnabled : false,
					hScrollBarEnabled : false
				}, {
					name : 'footer_tab_4',
					url : 'html/footer_tab_4.html',
					bounces : true,
					vScrollBarEnabled : false,
					hScrollBarEnabled : false
				}, {
					name : 'footer_tab_5',
					url : 'html/footer_tab_5.html',
					bounces : false,
					vScrollBarEnabled : false,
					hScrollBarEnabled : false,
				}]
			}, function(ret, err) {
				var footer = $api.byId('aui-footer');
				var footerAct = $api.dom(footer, '.aui-bar-tab li.active');
				$api.removeCls(footerAct, 'active');
				var name = ret.name;
				var index = ret.index;
					showHeader(index);
					header_h=$("header").height();
				var headerOffsetY=header_h+statusbarHeight;
				var footerOffsetY=body_h - header_h - footer_h-statusbarHeight;
				if (index == 0) {
					$api.addCls($api.byId('tabbar1'), 'active');
					api.setFrameGroupAttr({
					    name: 'footer_tab_nav',
					    rect : {
							x : 0, y : headerOffsetY, w : 'auto', h : footerOffsetY
						}
					});
				} else if (index == 1) {
					$api.addCls($api.byId('tabbar2'), 'active');
					api.setFrameGroupAttr({
					    name: 'footer_tab_nav',
					    rect : {
							x : 0, y : headerOffsetY, w : 'auto', h : footerOffsetY
						}
					});
				} else if (index == 2) {
					$api.addCls($api.byId('tabbar3'), 'active');
					api.setFrameGroupAttr({
					    name: 'footer_tab_nav',
					    rect : {
							x : 0, y : headerOffsetY, w : 'auto', h : footerOffsetY
						}
					});
				} else if (index == 3) {
					// $api.text($api.byId('header-title'), '进货单');
					$api.addCls($api.byId('tabbar4'), 'active');
					api.setFrameGroupAttr({
					    name: 'footer_tab_nav',
					    rect : {
							x : 0, y : headerOffsetY, w : 'auto', h : footerOffsetY
						}
					});
					// $(".header1").css({"display":"none"})
				} else if (index == 4) {
					$api.addCls($api.byId('tabbar5'), 'active');
					api.setFrameGroupAttr({
					    name: 'footer_tab_nav',
					    rect : {
							x : 0, y : 0, w : 'auto', h : body_h - header_h - footer_h
						}
					});
				}
			});
			//准备显示
			api.addEventListener({
			    name:'viewappear'
			}, function(ret, err){        
	   			api.setStatusBarStyle({
                  style : 'dark'
	            });
			});

			//登陆成功
			api.addEventListener({
				name : 'reGetMyInfo'
			}, function(ret) {
				if (ret && ret.value) {
					isLogin();

					//融云初始化
					rongyunListener();

					$api.setStorage('_server_url',serverUrl);

					// //推送设置
					// var ajpush = api.require('ajpush');
					// var param = {alias:'user0'};
					// ajpush.bindAliasAndTags(param,function(ret) {
					// 	var statusCode = ret.statusCode;
					// 	api.toast({msg:'jpush'+statusCode});
					// });
				}
			});
			//监听退出
            api.addEventListener({
                name : 'loginOut'
            }, function(ret, err) {
                if(ret&&ret.value){
                	$('.noMessage').removeClass('myMessage');

                	disConnect();

                    randomSwitchBtnBakHome(0);
				}
            });
			//监听云修复
			api.addEventListener({
				name : 'smartupdatefinish'
			}, function(ret, err) {
				api.toast({
					msg : '系统有新的更新了，请重新启动查看',
					duration : 2000,
					location : 'bottom'
				});
			});
			//网络断开的监听
			api.addEventListener({
				name : 'offline'
			}, function(ret, err) {
				api.toast({
					msg : '网络连接失败请检查您的网络',
					duration : 2000,
					location : 'bottom'
				});
			});
			// 选择颜色时候隐藏上下
			api.addEventListener({
				name:"showColor"
			},function(ret){
				if(ret&&ret.value){
					showColor();
				}
			})
			// 关闭颜色
			api.addEventListener({
				name:"closeColor"
			},function(ret){
				if(ret&&ret.value){
					closeColor();
				}
			});

		     //发布完成后
		     api.addEventListener({
		     	name: 'publishPostDone'
		     }, function(ret, err) {
		     	$('.header3 li[data-type="2"]').addClass('active').siblings('li').removeClass('active');
		     });

		     //清除消息数的监听
		     api.addEventListener({
		     	name: 'clearMessageCount'
		     }, function (ret) {
		     	$('.noMessage').removeClass('myMessage');
		     });


	        //<--- 融云聊天 --->
	        //融云2聊天监听模块
	        rong = api.require('rongCloud2');
	        getStorageAll();
	        if(user_id){
		        rongyunListener();
	        }
	        
	        api.addEventListener({
	            name : 'reRongCloudConnect'
	        }, function(ret, err) {
	            if (ret.value.key) {
	                rongyunListener();
	            }
	        });
	        
	        //获取历史消息
	        api.addEventListener({
	            name : 'getHistoryMessages'
	        }, function(ret, err) {
	            if (ret && ret.value) {
	                var value = ret.value;
	                getHistoryMessages(value.targetId, value.type);
	            }
	        });
	        
	        //监听发送消息功能
	        api.addEventListener({
	            name : 'sendMessage'
	        }, function(ret) {
	            if (ret && ret.value) {
	                var data = ret.value;
	                //目标id,消息内容,消息类型
	                sendMessage(data.targetId, data.conversationType, data.objectName, data.message);

	                //更新我发出的消息
	                switch(ret.value.objectName){
	                	//文字消息
	                	case 'RC:TxtMsg':
	                	data.message={text:data.message};
	                	break;
	                	//图片消息
	                	case 'RC:ImgMsg':
	                	data.message={imageUrl:data.message};
	                	break;
	                	//语音消息
	                	case 'RC:VcMsg':
	                	data.message={voicePath:data.message};
	                	break;
	                }
	                updateChatContentData(data.targetId,data.message,Date.parse(new Date()),true,data.isCompany);
	            }
	        });
	        
	        //断开连接
	        // api.addEventListener({
	        //     name : 'clearCart'
	        // }, function(ret, err) {
	        //     if (ret.value.key) {
	        //         disConnect();
	        //     }
	        // });
		}

		//显示顶部搜索
		function showSearch(){
		    api.openFrame({
		        name: 'html/search',
		        url: 'html/search.html',
		        vScrollBarEnabled: true,
		        pageParam:{
		        	fromIndex:true
		        },
		        animation:{
		        	type:'none'
		        }
		    });
		}

		//显示进货单编辑按钮
		function showCartButton(){
			$('.edit').show();
		}

		//隐藏进货单编辑按钮
		function hideCartButton(){
			$('.edit').hide();
		}

		//显示首页
		function showHome(){
			randomSwitchBtn($('#tabbar1'),'首页',0)
		}

		function randomSwitchBtn(obj, name, index) {
			getStorageAll();
			if(!user_id&&index>0){
				api.openWin({
					name : 'loginPass_win',
					url : 'html/loginPass_win.html'
				})
			}else{
				var pageParamVars={};
				if(index==1){
					api.execScript({
						frameName:'footer_tab_2',
						script:"onMenuTapped()"
					});
				}else if(index==2){
					api.execScript({
						frameName:'footer_tab_3',
						script:"onMenuTapped()"
					});
				}else if(index==4){
					api.execScript({
						frameName:'footer_tab_5',
						script:"checkNewInfo()"
					});
				}
				var footer = $api.byId('aui-footer');
				var footerAct = $api.dom(footer, '.aui-bar-tab li.active');
				$api.removeCls(footerAct, 'active');
				$api.addCls(obj, 'active');
				api.setFrameGroupIndex({
					name : 'footer_tab_nav',
					index : index,
					scroll : false,
					reload : false
				});
			}
		}

		//检查消息按钮
		function hasNewMessage(){
			api.execScript({
				frameName:'footer_tab_5',
				script:"checkNewInfo("+$('.noMessage').hasClass('myMessage')+")"
			});
		}

		function clearMessageCount(){
			$('.noMessage').removeClass('myMessage');
		}

		// 人脉圈的操作
		function changeAvatar(){
			api.execScript({
				frameName:'footer_tab_3',
				script:"changeAvatar()"
			})
		}
		// 人脉圈头部切换
		function headerChange(obj){
			$(obj).parent().children("li").removeClass("active");
			$(obj).addClass("active");
			var dataType=$(obj).attr("data-type");
			api.execScript({
				frameName:'footer_tab_3',
				script:"headerChange("+dataType+")"
			})

		}
		function randomSwitchBtnBakHome(index) {
			var footer = $api.byId('aui-footer');
			var footerAct = $api.dom(footer, '.aui-bar-tab li.active');
			$api.removeCls(footerAct, 'active');
			$api.addCls($api.byId('tabbar' + (index + 1)), 'active');
			api.setFrameGroupIndex({
				name : 'footer_tab_nav',
				index : index,
				scroll : false,
				reload : false
			});
		}

		//判断是否登录
		function isLogin() {
			getStorageAll();
			if (!user_id) {
				api.openWin({
					name : 'loginPass_win',
					url : 'html/loginPass_win.html',
					delay : 300
				})
			} else {
				// //更新位置信息
				// updateLocation();
			}
		}
		//显示不同的header
		function showHeader(type){
			$(".hidde").removeClass("showHeader");
			$(".header"+(parseInt(type)+1)).addClass("showHeader");
		}

		//动态圈的页头处理
		function changeHeader2(obj){
			$(obj).parent().find("li").removeClass("active");
			$(obj).addClass("active");
			var type=$(obj).attr("data-type");
			api.execScript({
				frameName:"footer_tab_2",
				script:'switchChange("'+type+'")'
			})
		}
		// 执行进货单的edit方法
		function edit(obj){
            if(typeof(obj)!='undefined'){
                var type="";
                if($(obj).text()=="编辑"){
                    $(obj).text("完成");
                    type="editing";
                }else{
                    $(obj).text("编辑");
                }
                api.execScript({
                    frameName:'footer_tab_4',
                    script:'edit("'+type+'")'
                })
            }else{
                $(".edit").text('编辑');
            }

		}
		//在进货单页面单击选择颜色时候的跨域，弹出操作
		function showColor(){
			api.setFrameGroupAttr({
				name:"footer_tab_nav",
				rect:{
					x : 0, 
					y : 0, 
					w : 'auto',
					h : 'auto'
				}
			})
		}

		// 在进货单页面单击选择颜色时候的跨域，关闭操作
		function closeColor(){
			api.setFrameGroupAttr({
				name:"footer_tab_nav",
				rect:{
					x : 0, 
					y : header_h, 
					w : 'auto', 
					h : body_h - header_h - footer_h
				}
			})
		}
        //执行跨域弹出遮罩层
        function  showLayer() {
            mask.show();
        }
        //执行跨域关闭遮罩层
        function  closeLayer() {
            mask.myclose();
        }


	    //<--- 融云聊天事件 --->
	    function rongyunListener() {
	        // userId = 10001
	        // portraitUri = 'https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png'
	        // token = 'tri9RGQkiRqOktPvT30CJblUXq/FwcHLWJ5NfRpLhw5gBWJrTNElV+PNbnsMfYlHajO8vpwOKBYD9rk5rqPuqw==';
	        
	        // userId = user_id;
	        // portraitUri = 'http://img1.360buyimg.com/pop/jfs/t3139/59/4944835986/18414/f3dd2c7c/585cd59cN8736ad36.jpg';
	        // token = 'xIF8C5hS8D6OktPvT30CJblUXq/FwcHLWJ5NfRpLhw5gBWJrTNElV63WPo4nG9LMajO8vpwOKBaGm0F8wENiUg==';
	        disConnect();
	        
	        //初始化
	        init();
	        //链接
	        connect();
	        //连接状态
	        connectStatus()
	        //监听所有信息
	        setOnReceiveMessageListener();
	    }
	    
	    //初始化
	    function init() {
	        rong.init(function(ret, err) {
	            // alert(JSON.stringify(ret));
	            if (ret.status == 'error') {
	                api.toast({
	                    msg : err.code
	                });
	            }
	        });
	    }
	    
	    //连接状态
	    function connectStatus() {
	        rong.setConnectionStatusListener(function(ret, err) {
	            
	            switch(ret.result.connectionStatus) {
	                case ('KICKED'):
						disConnect();
						$api.clearStorage();

	                    api.alert({
	                        title : '异常登录',
	                        msg : '用户账户在其他设备登录,本机会被踢掉线，请修改密码',
	                        buttons : ['确定']
	                    }, function(ret, err) {
	                        if (ret.buttonIndex == 1) {

								api.openWin({
									name : 'loginPass_win',
									url : 'html/loginPass_win.html'
								})
	                            // api.openWin({
	                            //     name : 'forget_win',
	                            //     url : 'html/forget_win.html'
	                            // });
	                        }
	                    });
	                    break;
//	                case ('NETWORK_UNAVAILABLE'):
//	                    api.toast({
//	                        msg : '网络不可用',
//	                        duration : 1000,
//	                        location : 'middle'
//	                    });
//	                    break;
//	                case ('SERVER_INVALID'):
//	                    api.alert({
//	                        title : '服务器异常',
//	                        msg : '服务器异常或无法连接',
//	                        buttons : ['确定']
//	                    }, function(ret, err) {
//
//	                    });
//	                    break;
	            }
	        });
	    }
	    
	    //消息的监听，监听到新消息后将消息广播出去，在会话页面监听接收并判断
	    var recevingRound=0;
    	var hasVibrated=false;
	    function setOnReceiveMessageListener() {
	        rong.setOnReceiveMessageListener(function(ret, err) {
	            //alert(JSON.stringify(ret));
	            if (ret) {
	                //alert(ret.result.message.targetId+','+talkingId);
	                //将监听到的消息广播出去，在会话页面接收
	                if(!hasVibrated){
	                	api.notification({
	                		vibrate : [500, 500]
	                	}, function(ret, err) {
			                    //alert(ret.id);
			                });
	                }
	                if(!recevingRound){
		                hasVibrated=true;
		                window.setTimeout(function(){
		                	hasVibrated=false;
		                },1500)
	                }
	                recevingRound++;
	                var str = JSON.stringify(ret.result);

	                //本地存储消息列表
	                if(ret.result.message.conversationType=='PRIVATE'){
		                updateChatContentData(ret.result.message.senderUserId,ret.result.message.content,ret.result.message.sentTime,false);
	                }

	                setTimeout(function() {
	                    api.execScript({
	                        name : 'chat_win',
	                        frameName : 'chat_frm',
	                        script : "getNewMessages('" + str + "')"
	                    });
	                }, 800)
	                api.parseTapmode();

	                $('.noMessage').addClass('myMessage');
	                api.execScript({
	                	frameName:'footer_tab_5',
	                	script:"checkNewInfo(1)"
	                });


	            }
	        })
	    }

	    function updateChatContentData(senderUserId,content,sentTime,unCount,isCompany){
	    	var oldContent=$api.getStorage('chatContent');
	    	oldContent=oldContent?oldContent:{};

	    	var newContent=new Array();
	    	if(oldContent){
	    		var newRow={};
	    		var unreadCount=0;
	    		for(i in oldContent){
            		//删除旧数据
            		if(oldContent[i].senderUserId==senderUserId){
            			unreadCount=oldContent[i].unreadCount;
            			continue;
            		}
            		newContent.unshift(oldContent[i]);
            	}
            	newRow.senderUserId=senderUserId;
            	newRow.content=content;
            	newRow.sentTime=sentTime;
            	newRow.isCompany=isCompany;
            	if(!unCount){
	            	newRow.unreadCount=unreadCount+1;
            	}else{
            		newRow.unreadCount=unreadCount;
            	}
            	newContent.unshift(newRow);
            }
            $api.setStorage('chatContent',newContent);


            api.sendEvent({
            	name: 'receiveChatMessage'
            });
	    }

	    function connect() {
	    	getStorageAll();
	        // var token = 'tri9RGQkiRqOktPvT30CJblUXq/FwcHLWJ5NfRpLhw5gBWJrTNElV+PNbnsMfYlHajO8vpwOKBYD9rk5rqPuqw==';
	        var token = rongcloud_token;

	        rong.connect({
	            token : '' + token + ''
	        }, function(ret, err) {
	            if (ret.status == 'success') {
	             //    api.toast({ msg: ret.result.userId });
	            } else {
	            	errCode=err.code;

	            	switch(errCode){
	            		case 31004: //重新获取token
	            		break;
						case 30015: //连接过于频繁
	            		break;
	            		default:
		                api.toast({ msg: '连接失败:'+errCode });
	            		break;
	            	}
	            }
	        });
	    }
	    
	    
	    //发送消息模块
	    function sendMessage(targetId, conversationType, objectName, message) {
	        //alert(targetId);
	        switch(objectName) {
	            //文字消息
	            case 'RC:TxtMsg':
	                rong.sendTextMessage({
	                    conversationType : conversationType,
	                    targetId : '' + targetId + '',
	                    text : message,
	                    extra : ''
	                }, function(ret, err) {
	                	onSentMessage(ret,err);
	                })
	                break;
	            //图片消息
	            case 'RC:ImgMsg':
	                rong.sendImageMessage({
	                    conversationType : '' + conversationType + '',
	                    targetId : '' + targetId + '',
	                    imagePath : message,
	                    extra : ''
	                }, function(ret, err) {
	                	onSentMessage(ret,err);
	                });
	                break;
	            //语音消息
	            case 'RC:VcMsg':
	                rong.sendVoiceMessage({
	                    conversationType : '' + conversationType + '',
	                    targetId : '' + targetId + '',
	                    voicePath : '' + message.path + '',
	                    duration : Number(message.duration),
	                    extra : ''
	                }, function(ret, err) {
	                	onSentMessage(ret,err);
	                });
	                break;
	                //商品信息
	            case 'RC:ImgTextMsg':
		             rong.sendRichContentMessage({
		             	conversationType: 'PRIVATE',
		             	targetId: '' + targetId + '',
		             	title: ''+message.title+'',
		             	description: ''+message.description+'',
		             	imageUrl: message.imageUrl,
		             	extra:message.extra
	                }, function(ret, err) {
	                	onSentMessage(ret,err);
	                });
	                break;
	        }
	    }

	    function onSentMessage(ret,err){
            if (ret.status == 'prepare') {
                var str = JSON.stringify(ret.result);
                api.execScript({
                    name : 'chat_win',
                    frameName : 'chat_frm',
                    script : "backSendMessage('" + str + "')"
                });
            } else if (ret.status == 'success') {
                // api.toast({
                //     msg : ret.result.message.messageId
                // });
            } else if (ret.status == 'error') {
            	if(ret.result.message){
            		api.execScript({
            			name : 'chat_win',
            			frameName : 'chat_frm',
            			script : "errorSendMessage('" + ret.result.message.messageId + "')"
            		});
            	}
            }
	    }

	    //获取某一会话的历史消息
	    function getHistoryMessages(targetId, type, oldestMessageId) {
	        rong.getHistoryMessages({
	            conversationType : type,
	            targetId : '' + targetId + '',
	            oldestMessageId : -1,
	            count : 30
	        }, function(ret, err) {
	            if (ret.status == 'success') {
	                //将获得的历史消息广播出去，在会话页面接收
	                api.sendEvent({
	                    name : 'backHistoryMessages',
	                    extra : {
	                        message : ret.result
	                    }
	                });
	            }
	        })
	    }

	    //断开连接
	    function disConnect() {
	        rong.disconnect({
	            isReceivePush : true
	        }, function(ret, err) {
	            if ('success' == ret.status) {
	                // api.toast({
	                //     msg : '断开连接成功!'
	                // });
	            }
	        });
	    }
	</script>
</html>